#include <stdio.h>
#include <stdlib.h>

#define MAX 100

struct Stack{
    int items[MAX];
    int top;
};

void initStack(struct Stack* stack){
    stack->top = -1;
}

int isFull(struct Stack* stack){
    return stack->top == MAX - 1;
}

int isEmpty(struct Stack* stack){
    return stack->top == -1;
}

void push(struct Stack* stack,int item){
    if(isFull(stack)){
        printf("Stack is full\n");
    }else{
        stack->items[++stack->top] = item;
    }
}

int pop(struct Stack* stack){
    if(isEmpty(stack)){
        printf("Stack is empty\n");
        return -1;
    }else{
        return stack->items[stack->top--];
    }
}

int peek(struct Stack* stack){
    if(isEmpty(stack)){
        return -1;
    }
    return stack->items[stack->top];
}


int main(){
    struct Stack s;
    initStack(&s);
    push(&s,10);
    push(&s,20);
    push(&s,30);
    printf("Top element is %d\n",peek(&s));
    printf("Popped element is \n");
    while (!isEmpty(&s))
    {
        printf("%d\n",pop(&s));
    }
}